﻿@{
    ViewBag.Title = "PayParam";
}

@section scripts
{
    <script src="@Url.Content("~/Scripts/shared/share.js")" type="text/javascript"></script> 
    <script src="@Url.Content("~/Scripts/shared/share.js")" type="text/javascript"></script> 
}

<form id="form1" method="post">
    <div class="mini-toolbar" style="padding:2px;border-top:0;border-left:0;border-right:0;"> 
        <table style="width:100%;">
            <tr>
                <td style="width:100%;">
                    <a class="mini-button" name="SaveInfo" iconCls="icon-save" onclick="SaveInfo" plain="true">保存</a>
                    
                    <a class="mini-button" iconCls="icon-close" onclick="CloseWindow" plain="true">关闭</a>
                </td>
            </tr>
        </table>                
    </div>      
    <div name="Base" title="支付参数设置" style="height:100%;overflow:hidden;margin-top:5px;margin-left:0px">
        <div id="tabs1" class="mini-tabs" activeIndex="0" style="width:100%;height:100%;" plain="false">
            <div title="前台支付参数" >
                 <table style="width:100%;">
                    <tr>
                        <td width="150px" height ="39px" align="right">
                            移动支付类型：</td>
                        <td width="300px" height ="39px">
                           <input id="FMobilePayID" name="FMobilePayID" class="mini-combobox" style="width:290px;" showNullItem="false" 
                                allowInput="false" align="left" value ="8" data ="dMobilePay"/>                         
                        </td>
                    </tr>
                    <tr>
                        <td width="150px" height ="39px" align="right">
                           下传到POS前台：</td>
                        <td width="300px" height ="39px">
                           <input id="FSendFlag" name="FSendFlag" class="mini-combobox" style="width:290px;" showNullItem="false" 
                                allowInput="false" align="left" value ="0" data ="dSendFlag"/> 
                        </td>
                    </tr>
                    <tr>
                        <td width="150px" height ="39px" align="right">商户编号：</td>
                        <td width="300px" height ="39px">
                            <input name="FStockNumber" id="FStockNumber" class="mini-textbox" style="width:290px;" value="" TabIndex="1"/>
                        </td>
                    </tr>
                    <tr>
                        <td width="150px" height ="39px" align="right">
                           密码或授权码：</td>
                        <td width="300px" height ="39px">
                            <input name="FKeyCode" id="FKeyCode" class="mini-textbox" style="width:290px;"  value="" TabIndex="4"/>
                        </td>
                    </tr>
                    <tr>
                        <td width="150px" height ="39px" align="right">
                           门店号或激活码：</td>
                        <td width="300px" height ="39px">
                            <input name="FShopNumber" id="FShopNumber" class="mini-textbox" style="width:290px;"  value="" TabIndex="4"/>
                        </td>
                    </tr>
                    <tr>
                        <td width="150px" height ="39px" align="right">
                           提示：</td>
                        <td width="300px" height ="39px">
                            保存成功后，前台要重新登录系统方可生效。
                        </td>
                    </tr>
                </table>
            </div>
            <div title="公众号微商城支付参数" >
                <table id="xjl_wap" style="width:100%;">
                    <tr>
                        <td width="150px" height="30px" align="right">服务商：</td>
                        <td width="300px" height="30px">
                            <input id="FWapPayType" name="FWapPayType" class="mini-combobox" style="width:290px;" showNullItem="false"
                             allowInput="false" align="left" value="6" data="dWapPayType" onvaluechanged="WapPayTypeChanged"/>
                        </td>
                    </tr>
                </table>
                <table id="wap_sqbdata" style="width:100%;">
                    <tr>
                        <td width="150px" height ="26px" align="right">
                            商户编号：</td>
                        <td width="300px" height ="26px">
                           <input name="Vendor_sn" id="Vendor_sn" class="mini-textbox" style="width:290px;" TabIndex="1"/>                        
                        </td>
                    </tr>
                    <tr>
                        <td width="150px" height ="26px" align="right">
                           商户密匙：</td>
                        <td width="300px" height ="26px">
                           <input id="Vendor_key" name="Vendor_key" class="mini-textbox " style="width:290px;" TabIndex="2"/> 
                        </td>
                    </tr>
                    <tr>
                        <td width="150px" height ="26px" align="right">激 活 码：</td>
                        <td width="300px" height ="26px">
                            <input name="Code" id="Code" class="mini-textbox" style="width: 290px;" TabIndex="3"/>
                        </td>
                    </tr>
                    <tr>
                        <td width="150px" height ="26px" align="right">
                           终 端 号：</td>
                        <td width="300px" height ="26px">
                           <input id="Terminal_sn" name="Terminal_sn" class="mini-textbox " style="width:290px;" enabled="false" TabIndex="4"/> 
                        </td>
                    </tr>
                    <tr>
                        <td width="150px" height ="26px" align="right">
                           终端密匙：</td>
                        <td width="300px" height ="26px">
                           <input id="Terminal_key" name="Terminal_key" class="mini-textbox " style="width:290px;" enabled="false" TabIndex="5"/> 
                        </td>
                    </tr>
                    <tr>
                        <td width="150px" height ="40px" align="right">
                            <a class="mini-button" name="SetSxbRemove" iconCls="icon-remove" onclick="SetSxbRemove" plain="true">注销激活</a>
                        </td>
                        <td width="300px" height ="40px">
                           <a class="mini-button" name="SetActivate" iconCls="icon-ok" style="margin-left:20px" onclick="SetActivate" plain="true">激活</a>
                        </td>
                    </tr>
                </table>      
                <table id="wap_sxfdata" style="width:100%; display:none;">
                    <tr>
                        <td width="150px" height ="26px" align="right">商户编号：</td>
                        <td width="300px" height ="26px">
                           <input name="FSxfShopNumber" id="FSxfShopNumber" class="mini-textbox" style="width:290px;" TabIndex="1"/>                        
                        </td>
                    </tr>
                </table>                
            </div>
            <div title="小程序支付参数(小精灵)">
                <table id="xjl" style="width:100%;">
                    <tr>
                        <td width="150px" height="39px" align="right">
                            服务商：
                        </td>
                        <td width="300px" height="39px">
                            <input id="FProvider" name="FProvider" class="mini-combobox" style="width:290px;" showNullItem="false"
                                   allowInput="false" align="left" value="1" data="dMerchant" onvaluechanged="MerchantChanged"/>
                        </td>
                    </tr>
                </table>
                <table id="xjldata" style="width:100%; display:none;">
                    <tr>
                        <td width="150px" height="39px" align="right">
                            商户编号：
                        </td>
                        <td width="300px" height="39px">
                            <input name="FMerchantCode" id="FMerchantCode" class="mini-textbox" style="width:290px;" TabIndex="1" />
                        </td>
                    </tr>
                    <tr>
                        <td width="150px" height="39px" align="right">
                            APPID：
                        </td>
                        <td width="300px" height="39px">
                            <input name="FAppID" id="FAppID" class="mini-textbox" style="width: 290px;" TabIndex="3" />
                        </td>
                    </tr>
                    <tr>
                        <td width="150px" height="39px" align="right">
                            Key：
                        </td>
                        <td width="300px" height="39px">
                            <input id="FKey" name="FKey" class="mini-textbox " style="width:290px;" TabIndex="2" />
                        </td>
                    </tr>
                </table>
                <table id="sxfdata" style="width:100%; display:none;">
                    <tr>
                        <td width="150px" height="39px" align="right">
                            商户编号：
                        </td>
                        <td width="300px" height="39px">
                            <input name="FMerchantMNO" id="FMerchantMNO" class="mini-textbox" style="width:290px;" TabIndex="2" />
                        </td>
                    </tr>
                </table>

            </div>
        </div>
            
    </div>
    <input name="CorpID" class="mini-hidden" />
</form>

<script>
    var dMerchant = [{ "id": "1", "text": "小精灵" },
        //{ "id": "2", "text": "收钱吧(在电商支付参数)" },
        { "id": "3", "text": "随行付" }];

    var dWapPayType = [{ "id": "6", "text": "收钱吧" },
        { "id": "11", "text": "随行付" }];

    var dMobilePay = [{ "id": "0", "text": "不定" },
                    { "id": "4", "text": "移动支付 SQB2.0" },
                    { "id": "5", "text": "移动收款 XJL" },
                    { "id": "6", "text": "移动支付 SQB.WebAPI" },
                    { "id": "7", "text": "移动支付 HMY.WebAPI" },
                    { "id": "8", "text": "移动支付 MY" },
                    { "id": "10", "text": "移动收款 XJL2.0" },
                    { "id": "11", "text": "移动收款 SXF" },
                    { "id": "12", "text": "移动收款 Fubei" }];

    var dSendFlag = [{ "id": "0", "text": "不下传到前台" },
                   { "id": "1", "text": "下传到前台" }];

    var FCorpID = "0";

    function FormShown() {
        mini.parse();
    }

    function MerchantChanged() {
        if (mini.getbyName("FProvider").getValue() == 1) {
            $("#xjldata").show();
            $("#sxfdata").hide();
        }
        else  {
            $("#xjldata").hide();
            $("#sxfdata").show();
        }
    }

    function WapPayTypeChanged() {
        if (mini.getbyName("FWapPayType").getValue() == 11) {
            $("#wap_sqbdata").hide();
            $("#wap_sxfdata").show();
        }
        else {
            $("#wap_sqbdata").show();
            $("#wap_sxfdata").hide();
        }
    }

    //加载资料
    function SetInfoData(data) {
        FCorpID = data.FItemID;
        $.post("GetPayParam", { FItemID: data.FItemID, mSystemAppID: parent.window.getSystemAppID() }, function (data) {
            var ret = mini.decode(data);
            var form = new mini.Form("form1");
            if (ret.data.length > 0) {
                form.setData(ret.data[0]);
            }
            else {
                mini.getbyName("CorpID").setValue(data.FItemID);
            }
            MerchantChanged();
            WapPayTypeChanged();
        });
    }

    function validate() {
        if (mini.getbyName("Vendor_sn").getValue() == '') {
            mini.alert("商户编号必须输入");
            return false;
        }
        if (mini.getbyName("Vendor_key").getValue() == '') {
            mini.alert("商户密匙必须输入");
            return false;
        }
        if (mini.getbyName("Code").getValue() == '') {
            mini.alert("激活码必须输入");
            return false;
        }
    }

    //保存资料
    function SaveInfo() {
        mini.getbyName("SaveInfo").disable();
        mini.getbyName("CorpID").setValue(FCorpID);

        var mType = mini.getbyName("FMobilePayID").getValue();

        var form = new mini.Form("#form1");
        var data = form.getData(true, false);
        var json = mini.encode(data);
        $.post("SavePayParam", { json: json, mSystemAppID: parent.window.getSystemAppID() }, function (data) {
            var ret = mini.decode(data);
            if (ret.status == 1) {
                mini.showTips({ content: "保存成功", state: "success", x: "center", y: "top", timeout: 3000 });
                var data = mini.decode(ret.msg);
                mini.getbyName("Terminal_sn").setValue(data.Terminal_sn);
                mini.getbyName("Terminal_key").setValue(data.Terminal_key);
            }
            else {
                mini.alert(ret.msg);
            }
            mini.getbyName("SaveInfo").enable();
        });
    }

    function SetActivate() {
        mini.getbyName("SetActivate").disable();
        mini.getbyName("CorpID").setValue(FCorpID);
        var form = new mini.Form("#form1");
        if (validate() == false) {
            mini.getbyName("SetActivate").enable();
            return;
        }
        var data = form.getData(true, false);
        var json = mini.encode(data);
        $.post("ActionPay", { json: json, mSystemAppID: parent.window.getSystemAppID() }, function (data) {
            var ret = mini.decode(data);
            if (ret.status == 1) {
                mini.showTips({ content: "激活成功", state: "success", x: "center", y: "top", timeout: 3000 });
                var data = mini.decode(ret.msg);
                mini.getbyName("Terminal_sn").setValue(data.Terminal_sn);
                mini.getbyName("Terminal_key").setValue(data.Terminal_key);
            }
            else {
                mini.alert(ret.error);
            }
            mini.getbyName("SetActivate").enable();
        });
    }
    
    function SetSxbRemove() {
        mini.getbyName("SetSxbRemove").disable();
        mini.getbyName("CorpID").setValue(FCorpID);
        var form = new mini.Form("#form1");
        var data = form.getData(true, false);
        var json = mini.encode(data);
        $.post("SetSxbRemove", { json: json, mSystemAppID: parent.window.getSystemAppID() }, function (data) {
            var ret = mini.decode(data);
            if (ret.status == 1) {
                mini.showTips({ content: "注销成功", state: "success", x: "center", y: "top", timeout: 3000 });
                var data = mini.decode(ret.msg);
                mini.getbyName("Terminal_sn").setValue(data.Terminal_sn);
                mini.getbyName("Terminal_key").setValue(data.Terminal_key);
            }
            else {
                mini.alert(ret.error);
            }
            mini.getbyName("SetActivate").enable();
        });
    }

</script>